#!/bin/bash

function configureDNSResto {
    cd DNS/hosts/resto
	./configurar.sh
    cd ../../..
}

function configureDNSSaladas {
	cd DNS/hosts/saladas
	./configurar.sh
	cd ../../..
}


function configureServers {
while : 
do
    echo "Elige una opccion:"
    echo "1. WEB SERVER"
    echo "2. FTP SERVER"
    echo "3. TELNET SERVER"
    echo "4. Salir"
	
    read -n1 opcion
    case $opcion in
        1) echo "Configuring Web Server";
           echo "WEB-SERVER" > /etc/hostname
		   ./web.sh
		   configureDNSResto
           exit;;
        2) echo "Configuring FTP Server";
           echo "FTP-SERVER" > /etc/hostname
		   ./ftp.sh
		   configureDNSSaladas  
           exit;;
        3) echo "Configuring Telnet Server";
           echo "TEL-SERVER" > /etc/hostname
		   ./telnet.sh
		   configureDNSResto
           exit;;
        4) echo;
	   break;;

        *) echo "Error: Elige una opcion valida [1-4]";
           echo;
           echo;;
    esac
done


}

function configureHosts {
while : 
do
    echo "Elige una opccion:"
	echo "1. Host A"
	echo "2. Host B"
	echo "3. Host C"
    echo "4. Salir"
	
    read -n1 opcion
    case $opcion in
        1) echo "Configuring Host A";
           echo "HOST-A" > /etc/hostname
		   ./hostA.sh
		   configureDNSResto
           exit;;
        2) echo "Configuring Host B";
           echo "HOST-B" > /etc/hostname
		   ./hostB.sh
		   configureDNSSaladas
           exit;;
        3) echo "Configuring Host C";
           echo "HOST-C" > /etc/hostname
		   ./hostC.sh
		   configureDNSResto
           exit;;

        4) echo;
           break;;
        *) echo "Error: Elige una opcion valida [1-4]";
           echo;
           echo;;
    esac
done
}

# Main 

clear
# Setting all files as executable
chmod +wrx * -R

while :
do
    echo "Elige una opccion:"
    echo "1. H104"
    echo "2. H105"
    echo "3. H108"
	echo "4. H116"
	echo "5. H124"
	echo "6. H132"
	
	echo "7. SERVERS"
	echo "8. HOSTS"
	
    echo "9. Salir"
	
    read -n1 opcion
    case $opcion in
        1) echo "Configuring H104";
		   echo "H104" > /etc/hostname
		   ./RuteoH104.sh
		   cd DNS/nivel2/saladas
		   ./configurar.sh
		   cd ../../..
		   configureDNSSaladas
           exit;;
        2) echo "Configuring H105";
		   echo "H105" > /etc/hostname
           ./RuteoH105.sh
		   configureDNSSaladas
           exit;;
        3) echo "Configuring H108";
           echo "H108" > /etc/hostname
		   ./RuteoH108.sh
		   configureDNSSaladas
           exit;;
        4) echo "Configuring H116";
           echo "H116" > /etc/hostname
           ./RuteoH116.sh
		   cd DNS/root
		   ./configurar.sh
		   cd ../..
		   configureDNSResto
           exit;;
        5) echo "Configuring H124";
           echo "H124" > /etc/hostname
           ./RuteoH124.sh
		   configureDNSResto
           exit;;
        6) echo "Configuring H132";
           echo "H132" > /etc/hostname
           ./RuteoH132.sh
		   cd DNS/nivel2/resto
		   ./configurar.sh
		   cd ../../..
		   configureDNSResto
           exit;;
        7) echo;
		   configureServers;
           exit;;

        8) echo;
		   configureHosts;
           exit;;

	9) echo; echo "Bye!";
           exit;;

        *) echo "Error: Elige una opcion valida [1-9]";
           echo;
           echo;;
    esac
done



